<!-- BEGIN PAGE HEADER-->
<style>
    .ibox label {
        margin-left: 8px;
        margin-bottom: 8px;
    }
</style>
<?php $this->load->view('partials/breadcrumb.tpl', Array('_NO_IOSS_NEW' => '1')) ?>
<!-- END PAGE HEADER-->
<!-- BEGIN PAGE CONTENT-->
<script type="text/javascript">
    function defConfirm(url) {
        if (!confirm("确定要删除吗？")) {
            return false;
        }
        window.location.href = url;
        return true;
    }

    $(document).ready(function () {
        $("#reset").click(function () {
            $("select").val('');
            $("input[type='text']").val('');
        });
    });
</script>
<div class="row">
    <div class="col-xs-12">
        <!-- Begin: life time stats -->
        <div class="portlet">
            <?= form_open('', Array('class' => 'form-inline', 'role' => 'form')) ?>
            <?= search_form_input('task_id', filterValue('task_id'), '任务ID', 'class="form-control input-xs"'); ?>
            <?= search_form_input('order_no', filterValue('order_no'), '买家下单号', 'class="form-control input-xs"'); ?>
            <?php if ($this->_user->role_id == 1): ?>
                <?= search_form_dropdown('operator_id', array('' => '接单者...') + $allReviewsAdmin, filterValue('operator_id') ? filterValue('operator_id') : ($currentRoleId != 1 ? $currentAdminId : ''), '接单者', 'class="form-control input-xs"'); ?>
            <?php endif; ?>
            <?= search_form_dropdown('group_id', array('' => '所属销售组...') + $allSaleGroups, filterValue('group_id'), '所属销售组', 'class="form-control input-xs"'); ?>
            <?= search_form_dropdown('shop_id', array('' => '所属店铺...') + $allShops, filterValue('shop_id'), '所属店铺', 'class="form-control input-xs"'); ?>
            <?= search_form_input('taskoperate_number_perpage', filterValue('taskoperate_number_perpage'), '每页显示条数', 'class="form-control input-xs"'); ?>
            <div style="clear:both;height:10px;"></div>
            <?= search_form_dropdown('status', array('' => '选择状态...') + MTaskOperate::getState(), filterValue('status'), '状态', 'class="form-control input-xs"'); ?>
            <?= search_form_dropdown('payment_type', array('' => '选择付款类型...') + IOSS_StaticConfig::$payTypeArray, filterValue('payment_type'), '付款类型', 'class="form-control input-xs"'); ?>
            <?= search_form_dropdown('pay_method', array('' => '选择打款方式...') + IOSS_StaticConfig::$payMethod, filterValue('pay_method'), '打款方式', 'class="form-control input-xs"'); ?>
            <div style="clear:both;height:10px;"></div>

            <div class="input-group input-large date-picker input-daterange" data-date="" data-date-format="yyyy-mm-dd">
                <input type="text" class="form-control" name="pay_request_create_time_begin"
                       value="<?= filterValue('pay_request_create_time_begin') ?>" placeholder="申请开始时间"
                       autoComplete="off">
                <span class="input-group-addon">to </span>
                <input type="text" class="form-control" name="pay_request_create_time_end" value="<?= filterValue('pay_request_create_time_end') ?>" placeholder="申请结束时间" utoComplete="off">
            </div>

            <div class="input-group input-large date-picker input-daterange" data-date="" data-date-format="yyyy-mm-dd">
                <input type="text" class="form-control" name="pay_request_update_time_begin" value="<?= filterValue('pay_request_update_time_begin') ?>" placeholder="处理开始时间" autoComplete="off">
                <span class="input-group-addon">to </span>
                <input type="text" class="form-control" name="pay_request_update_time_end" value="<?= filterValue('pay_request_update_time_end') ?>" placeholder="处理结束时间" autoComplete="off">
            </div>
            <label style="float: right;margin-right: 20px" class="label label-danger">总计<?= $total_number ?>条</label>
            <button type="button" class="btn default" id="reset">重置条件</button>
            <button type="submit" class="btn green about_search">搜索 <i class="fa fa-search"></i></button>
            <button type="button" class="btn purple" onclick="iBox()">导出选项</button>
            <button id="ajax_merge" type="button" class="btn red">合并提交</button>
            <button id="import_xls" type="button" class="btn blue">测评导入</button>
            <script>
                function iBox() {
                    $('#choose-field').toggle(500, 'swing')
                }

                $("#import_xls").click(function () {
                    $("#importModal").modal();
                });
            </script>
            <?= form_close() ?>
            <div style="display:none;" class="portlet-body" id="choose-field">
                <form action="" method="post" id="export_form">
                    <div class="well well-sm" style="margin: 10px 0;">
                        <div class="checkbox" style="margin-bottom: 15px;">
                            <b><i>请选择要导出的字段：</i></b>
                            <label>
                                <input id="all" type="checkbox">
                                全选/全不选
                            </label>
                        </div>
                        <div class="checkbox ibox">
                            <label>
                                <input class="fbox" name="field[]" value="id" type="checkbox">id
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="operator_id" type="checkbox">接单人
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="task_id" type="checkbox">任务ID
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="task_id" type="checkbox">所属任务
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="asin" type="checkbox">任务sain
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="product_image" type="checkbox">任务图片
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="comment_link" type="checkbox">评论连接
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="shop_id" type="checkbox">店铺
                            </label>

                            <label>
                                <input class="fbox" name="field[]" value="payment_type" type="checkbox">打款类型
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="pay_method" type="checkbox">打款方式
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="order_no" type="checkbox">订单编号
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="buyer_order_time" type="checkbox">买手下单时间
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="buyer_pay_time" type="checkbox">买手付款时间
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="true_product_price" type="checkbox">购买时商品价格
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="buyer_pay_total" type="checkbox">买手下单支付费用
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="yunfei" type="checkbox">运费
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="buyer_pay_coin_type" type="checkbox">买家付款币种
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="pay_account" type="checkbox">买家收款账户
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="contact" type="checkbox">买家联系方式
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="true_shuadan_amount" type="checkbox">刷单应付买家
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="commission" type="checkbox">买家佣金
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="coin_type" type="checkbox">买家收款币种
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="rate_rmb" type="checkbox">对人民币汇率
                            </label>

                            <label>
                                <input class="fbox" name="field[]" value="true_company_cost" type="checkbox">公司实际刷单成本
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="true_company_cost_rate" type="checkbox">公司成本对rmb汇率
                            </label>

                            <label>
                                <input class="fbox" name="field[]" value="intror_pay_account" type="checkbox">中介收款账户
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="intror_contact" type="checkbox">中介联系方式
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="intror_commission" type="checkbox">中介佣金
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="intror_coin_type" type="checkbox">中介收款币种
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="intror_rate_rmb" type="checkbox">中介费对人民币汇率
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="add_image" type="checkbox">付款图
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="add_image_1" type="checkbox">付款图1
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="add_image_2" type="checkbox">付款图2
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="add_image_3" type="checkbox">付款图3
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="add_image_4" type="checkbox">付款图4
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="add_image_5" type="checkbox">付款图5
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="status" type="checkbox">状态
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="remark" type="checkbox">备注
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="create_time" type="checkbox">创建时间
                            </label>
                            <label>
                                <input class="fbox" name="field[]" value="update_time" type="checkbox">更新时间
                            </label>
                            <input type="hidden" name="file_name" value="ce_ping_">
                            <input type="hidden" name="page_name" value="tasks.taskoperate.index">
                            <input type="hidden" name="excel_type" value="TaskOperateExport">
                        </div>
                        <div class="text-right">
                            <button id="export-xls" type="button" class="text-right btn blue-madison">导出xls</button>
                        </div>
                        <script>
                            $('#export-xls').click(function () {
                                var data = $('#export_form').serialize();
                                if (data.indexOf('field') == -1) {
                                    toastr.error('请选择要导出的字段！', '失败');
                                    return false;
                                } else {
                                    var x = 1;
                                    var y = 1;
                                    $('#process').modal('show');
                                    setInterval(function () {
                                        x += parseFloat(Math.random(0, 1));
                                        var width = x.toFixed(2) + '%';
                                        if (parseInt(x) >= 99) {
                                            x = y / (y + 1) * 100;
                                            y++;
                                        }
                                        $('#show-process').html(width);
                                        $('#show-process').css('width', width)
                                    }, 1000);
                                    $.ajax({
                                        url: '<?=site_url("/common/ExcelExport/excel_export")?>',
                                        data: $('#export_form').serialize(),
                                        method: 'POST',
                                        dataType: 'json',
                                        success: function (output) {
                                            clearInterval();
                                            $('#show-process').html('100%');
                                            $('#show-process').css('width', '100%');
                                            $('#process').modal('hide');
                                            toastr.success(output.msg, '成功');
                                            // console.log(output);
                                            // return;
                                            document.location.href = '/' + output.url;
                                        },
                                        fail: function (data) {
                                            toastr.error(data.msg, '失败')
                                        }
                                    })
                                }
                            });

                            $('#all').click(function () {
                                if ($(this).prop("checked") == true) {
                                    $(".fbox").prop('checked', true);
                                    $(".fbox").parent('span').addClass('checked');
                                    return;
                                } else {
                                    $(".fbox").prop('checked', false);
                                    $(".fbox").parent('span').removeClass('checked');
                                    return;
                                }
                            });
                        </script>
                    </div>
                </form>
            </div>
            <div class="portlet-body">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="table-scrollable">
                            <form id="ajax_merge_form" action="" method="post" onsubmit="return false">
                                <table class="table table-hover table-bordered table-striped">
                                    <thead>
                                    <tr>
                                        <th width="1%">
                                            <label>
                                                <input type="checkbox" id="merge_all" ">
                                            </label>
                                        </th>
                                        <th width="2%">ID</th>
                                        <!--                                        <th width="3%">任务ID</th>-->
                                        <th width="8%">商品名称</th>
                                        <th width="5%">店铺</th>
                                        <th width="5%">接单者</th>
                                        <th width="6%">买家下单号</th>
                                        <th width="5%">付款类型</th>
                                        <th width="5%">状态</th>
                                        <th width="6%">创建时间</th>
                                        <th width="6%">更新时间</th>
                                        <th width="12%">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <?php foreach ($list as $v) { ?>
                                        <tr>
                                            <td>
                                                <input type="checkbox" class="mbox" name="ceping_ids[]"
                                                       value="<?= $v->id ?>" title="ID:<?= $v->id ?>">
                                            </td>
                                            <td><?= $v->id ?></td>
                                            <td>
                                                <a style="color:#008200;"
                                                   href="<?= site_url('/tasks/task/view/' . $v->task_id) ?>"><?= $v->product_name ?>
                                                </a>
                                            </td>
                                            <td><?= $allShops[$v->shop_id] ?></td>
                                            <td><?= $allReviewsAdmin[$v->operator_id]; ?></td>
                                            <td><?= $v->order_no ?></td>

                                            <td class="text-center popovers" data-container="body" data-trigger="hover" data-placement="top" data-content="<?= IOSS_StaticConfig::$payTypeArray[$v->payment_type] ?>"><?= $v->payment_type; ?></td>
                                            <td class="text-center"><?= MTaskOperate::getState($v->status); ?></td>
                                            <td><?= date('Y-m-d H:i:s', $v->create_time) ?></td>
                                            <td><?= ($v->create_time == $v->update_time && $v->update_time !== 0) ? '' : date('Y-m-d H:i:s', $v->update_time) ?></td>
                                            <td title="状态为0，1才可以编辑">
                                                <a href="javascript:ioss_url_modal('<?= site_url('/tasks/taskoperate/ajaxViewDetail/' . $v->id) ?>');"
                                                   class="btn btn-sm blue <?= $p->read ? '' : 'disabled' ?>">
                                                    <i class="fa fa-play"></i> 查看</a>
                                                <a href="<?= site_url('/tasks/taskoperate/edit/' . $v->id) ?>"
                                                   class="btn btn-sm purple <?php
                                                   if (in_array($v->status, array(0, 1)) && $p->edit && $v->operator_id == $this->_user->id) {
                                                       echo '';
                                                   } else {
                                                       echo 'disabled';
                                                   }
                                                   ?>"><i class="fa fa-edit"></i> 编辑</a>
                                            </td>
                                        </tr>
                                    <?php } ?>
                                    </tbody>
                                </table>
                            </form>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12 text-right">
                        <?= $pagination ?>
                    </div>
                </div>
            </div>
        </div>
        <!-- End: life time stats -->
    </div>
</div>

<div class="modal fade" id="importModal">
    <div class="modal-dialog" role="document">
        <form method="post" action="<?= site_url('tasks/taskoperate/importExcel') ?>" enctype="multipart/form-data">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span>
                    </button>
                    <h4 class="modal-title" id="exampleModalLabel">测评导入</h4>
                </div>
                <div class="modal-body">
                    <div><p>点击此处下载表格模板文件 <b><a style="color: #3a5aff;" href="/upload/ceping_example.xls">ceping_example.xls</a><span style="color: red;">   （必须使用此表格进入导入操作！）</span></b>
                        </p>
                        <p style="color: #ff3761;">*打款类型对照：</p>
                        <ul>
                            <li><b>1 => 只付货款（买手只完成下单，就来要求打货款情况）</b></li>
                            <li><b>2 => 付货款+一半佣金（买手要求付货款和一半佣金后，才愿意去评论）</b></li>
                            <li><b>3 => 付佣金，（对应1已付货款，买手已测评过来找测评付全部佣金）</b></li>
                            <li><b>4 => 付剩余一半佣金（对应2已付货款+一半佣金，买手完成测评后，把剩余佣金支付的申请）</b></li>
                            <li><b>5 => 付货款+佣金（买手完成下单并完成测评之后才来联系测评要钱的申请）</b></li>
                            <li><b>6 => 付货款+佣金+中介费（中介联系的买手完成全部流程后一次性支付所有费用）</b></li>
                            <li><b>7 => 付中介费（完成流程后，未付中介费的，另外生成付中介费）</b></li>
                            <li><b>8 => 付佣金+中介费（对应1已付货款，中介介绍买手付全部佣金+中介费的申请）</b></li>
                            <li><b>9 => 付一半佣金+中介费（对应2已付货款+一半佣金，中介介绍的买手付剩余佣金+中介费的申请 ）</b></li>
                        </ul>

                        <div class="col-md-6">
                            <p style="color: #ff3761;">*币种对照：</p>
                            <ul>
                                <li><b> 1 => 美元</b></li>
                                <li><b> 2 => 欧元</b></li>
                                <li><b> 3 => 人民币</b></li>
                                <li><b> 4 => 英镑</b></li>
                                <li><b> 5 => 日元</b></li>
                                <li><b> 6 => 加元</b></li>
                            </ul>
                        </div>
                        <div class="col-md-6">
                            <p style="color: #ff3761;">*打款方式对照：</p>
                            <ul>
                                <li><b> 1 => PayPal</b></li>
                                <li><b> 2 => 银联</b></li>
                                <li><b> 3 => 支付宝</b></li>
                                <li><b> 4 => 微信</b></li>
                            </ul>
                        </div>
                        <div class="col-md-12">
                            <p style="color: #ff3761;">*测评类型对照：</p>
                            <ul>
                                <li><b> 1 => 销量</b></li>
                                <li><b> 2 => 测评</b></li>
                            </ul>
                        </div>
                        <div class="col-md-12">
                            <p style="color: #ff3761;">*时间格式（年月时以/隔开）：</p>
                            <ul>
                                <li><b>2019/02/01</b></li>
                            </ul>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="recipient-name" class="control-label"></label>
                        <input type="file" name="file" class="form-control">
                    </div>
                    <input type="hidden" name="operator_id" value="<?= $this->_user->id ?>">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary">确认导入</button>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="modal fade bs-example-modal-lg" id="process" data-backdrop="static" style="margin-top: 20%" tabindex="-1"
     role="dialog" aria-labelledby="myLargeModalLabel">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">

            <div class="progress progress-striped active" style="height: 20px;">
                <div class="progress-bar progress-bar-info" style="width:0;" role="progressbar" aria-valuenow="0"
                     aria-valuemax="100" aria-valuemin="0" id="show-process">0%
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $('.img-rounded').zoomify();
    });

    $('#ajax_merge').click(function () {
        var data = $('#ajax_merge_form').serialize();
        if (!data) {
            toastr.error('请选择要合并的测评记录', '失败');
            return;
        }

        $.ajax({
            url: '<?=site_url("/tasks/taskoperate/group_cepings")?>',
            data: data,
            method: 'POST',
            dataType: 'json',
            success: function (data) {
                if (data.status) {
                    toastr.success(data.msg, '成功');
                    setTimeout(function () {
                        location.href = '/finance/apply/add';
                    }, 1000)
                } else {
                    toastr.error(data.msg, '失败')
                }
            },
            fail: function (e) {
                toastr.error(data.msg, '失败')
            }
        })
    });

    $('#merge_all').click(function () {
        if ($(this).prop("checked") == true) {
            $(".mbox").prop('checked', true);
            $(".mbox").parent('span').addClass('checked');
            return;
        } else {
            $(".mbox").prop('checked', false);
            $(".mbox").parent('span').removeClass('checked');
            return;
        }
    });
</script>
<!-- END PAGE CONTENT-->
